const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
    mode: 'production',
    entry: {
        main: './src/index.js',
        sub: './src/index.js'
    },
    module: {
        rules: [{
            test: /\.jpg|png|gif$/,
            use: {
                loader: 'url-loader',
                options: {
                    // placeholder 占位符  要加引号
                    name: '[name]_[hash].[ext]',
                    outputPath: "images/",
                    limit: 204800  // 200kb大小
                }
            }

        },
        {
            test: /\.eot|ttf|svg$/,
            use: {
                loader: 'file-loader',
                options: {
                    name: '[name].[ext]',
                }
            }

        }, {
            test: /\.vue$/,
            use: {
                loader: 'vue-loader'
            }

        },
        {
            // loader执行是从下到上，从右到左
            test: /\.scss$/,
            use: ['style-loader',
                {
                    loader: 'css-loader',
                    options: {
                        importLoaders: 2,
                    }
                },
                'sass-loader',
                'postcss-loader'
            ]

        }
        ]
    },
    plugins: [new HtmlWebpackPlugin({
        template: 'src/index.html'
    }), new CleanWebpackPlugin()],
    output: {
        publicPath:'http://cdn.com.cn',
        filename: '[name].js',
        path: path.resolve(__dirname, 'dist')
    }
} 